#include "objectswidget.h"

ObjectsWidget::ObjectsWidget(QWidget *parent) :
    QWidget(parent)
{
    main_layout = new QVBoxLayout();

    QComboBox *templateBox = new QComboBox();
    templateBox->addItem("Copa");
    templateBox->addItem("Botella");
    templateBox->addItem("Silla");

    copawidget = new CopaWidget(new Copa);
    botellawidget = new BotellaWidget(new Botella);
    sillawidget = new SillaWidget(new Silla);

    main_layout->addWidget(templateBox);
    main_layout->addWidget(copawidget);
    main_layout->addWidget(botellawidget);
    main_layout->addWidget(sillawidget);

    ChangeObject("Copa");

    setLayout(main_layout);

    connect(botellawidget,SIGNAL(Updated()),
            this,SLOT(Update()));

    connect(copawidget,SIGNAL(Updated()),
            this,SLOT(Update()));

    connect(sillawidget,SIGNAL(Updated()),
            this,SLOT(Update()));

    connect(templateBox,SIGNAL(currentIndexChanged(QString)),
            this,SLOT(ChangeObject(QString)));
}

void ObjectsWidget::Update(){
    emit Updated();
}

void ObjectsWidget::ChangeObject(const QString &nombre){
    HideAllWidgets();

    if (nombre=="Copa") {
        copawidget->show();
        emit ObjectChanged(copawidget->GetModel());
    } else if (nombre=="Botella") {
        botellawidget->show();
        emit ObjectChanged(botellawidget->GetModel());
    } else if (nombre=="Silla") {
        sillawidget->show();
        emit ObjectChanged(sillawidget->GetModel());
    }

}

void ObjectsWidget::HideAllWidgets(){
    copawidget->hide();
    botellawidget->hide();
    sillawidget->hide();
}
